<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_block_front_MenuEditAction extends m_backoffice_extends_BlockEditModal
{
	public function execute()
	{
        $formValues = $this->getFormValues('form');

        $this->addToModel('menus', $this->getMenusList());

        if(count($formValues) > 0)
        {
            $block = $this->getBlock();

            $block['menu'] = $formValues['menu'];
            $block['depth'] = $formValues['depth'];
            $block['title'] = $formValues['title'];
            $block['activeParent'] = $formValues['activeParent'];

            $this->saveBlock($block);
            $this->closeModal();
        }

        $this->setModalParameters();
        $this->setView('success');
	}

    private function getMenusList()
    {
        $menus = array();
        $page = $this->getPage();

        $menus[] = $page->getWebsite();

		$allMenus = f_document_Provider::getInstance()	->loadDocuments("modules_website/menu")
                                                        ->whereIsEqual("websiteId", $page->getWebsiteId())
                                                        ->retrieveDocuments($page->getLang());

        return array_merge($menus, $allMenus);
    }
}